<?php
namespace app\controllers\api\upload;

use fate\http\Request;
use app\libs\LibUser;
use app\libs\Util;
use app\models\Files;

// 保存到数据库
class SaveController extends \app\controllers\ForceLoginPure {
    public function run() {
        global $_G;

        $req = Request::getInstance();

        $uid = LibUser::getLoginUid();
        $projectId = Util::plainText($req->getParameter('project_id'));
        $uri = Util::plainText($req->getParameter('uri'));
        $ip = Util::plainText($req->getUserIP());

        if(!is_numeric($projectId)) {
            $this->ajaxReturn(null, 300002);
            exit;
        }

        $ret = [
            'uid' => $uid,
            'uri' => $uri,
            'upload_ip' => $ip,
            'project_id' => $projectId,
            'post_time' => $_G['now_time']
        ];

        $file = new Files();
        $file->insert($ret);

        $this->ajaxReturn(null);
    }
}
